/******************************************************************************
 Copyright (c) 2021-2025 Qualcomm Technologies International, Ltd.
 All Rights Reserved.
 Qualcomm Technologies International, Ltd. Confidential and Proprietary.

******************************************************************************/

#include "csr_bt_gatt_lib.h"

#include "gatt_battery_server_private.h"
#include "gatt_battery_server_access.h"
#include "gatt_battery_server_db.h"
#include "csr_log_text_2.h"

/***************************************************************************
NAME
    sendBatteryAccessRsp

DESCRIPTION
    Send an access response to the GATT library.
*/
static void sendBatteryAccessRsp(CsrBtGattId gattId,
                                    uint32 btConnId,
                                    uint16 handle,
                                    uint16 result,
                                    uint16 size_value,
                                    uint8 *value)
{
    CsrBtGattDbReadAccessResSend(gattId,
                                 btConnId,
                                 handle,
                                 result,
                                 size_value,
                                 value);
}

/***************************************************************************
NAME
    sendBatteryWriteAccessErrorRsp

DESCRIPTION
    Send a write access error response to the GATT library.
*/
static void sendBatteryWriteAccessErrorRsp(const GBASS *battery_server, const CsrBtGattDbAccessWriteInd* access_ind, uint16 error)
{
    CsrBtGattDbWriteAccessResSend(battery_server->gattId,
                                  access_ind->btConnId,
                                  access_ind->attrHandle,
                                  error);
}

/***************************************************************************
NAME
    sendBatteryReadAccessErrorRsp

DESCRIPTION
    Send a read access error response to the GATT library.
*/
static void sendBatteryReadAccessErrorRsp(const GBASS* battery_server, const CsrBtGattDbAccessReadInd* access_ind, uint16 error)
{
    CsrBtGattDbReadAccessResSend(battery_server->gattId,
                                 access_ind->btConnId,
                                 access_ind->attrHandle,
                                 error,
                                 0,
                                 NULL);
}

/***************************************************************************/
void sendBatteryLevelAccessRsp(const GBASS* battery_server, uint32 cid, uint8 battery_level, uint16 result)
{
    uint8* value = (uint8*)CsrPmemAlloc(GATT_BATTERY_LEVEL_OCTET_SIZE);
    SynMemCpyS(value, GATT_BATTERY_LEVEL_OCTET_SIZE, &battery_level, GATT_BATTERY_LEVEL_OCTET_SIZE);
    sendBatteryAccessRsp(battery_server->gattId, cid, HANDLE_BATTERY_LEVEL, result, GATT_BATTERY_LEVEL_OCTET_SIZE, value);
}

#ifdef EXCLUDE_GATT_BATTERY_SERVICE_V1P1

/***************************************************************************
NAME
    batteryLevelAccess

DESCRIPTION
    Deals with access of the HANDLE_BATTERY_LEVEL handle.
*/
static void batteryLevelReadAccess(GBASS* battery_server, const CsrBtGattDbAccessReadInd* access_ind)
{
    /* Send read level message to app_task so it can return the current level */
    MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_READ_LEVEL_IND);
    message->battery_server = battery_server;     /* Pass the instance which can be returned in the response */
    message->cid = access_ind->btConnId;         /* Pass the CID which can be returned in the response */
    BasMessageSend(battery_server->app_task, GATT_BATTERY_SERVER_READ_LEVEL_IND, message);
}

/***************************************************************************
NAME
    batteryClientConfigWriteAccess

DESCRIPTION
    Deals with access of the HANDLE_BATTERY_LEVEL_CLIENT_CONFIG handle.
*/
static void batteryClientConfigWriteAccess(GBASS* battery_server, const CsrBtGattDbAccessWriteInd* access_ind)
{
    if (access_ind->writeUnit[0].valueLength == GATT_CLIENT_CONFIG_OCTET_SIZE)
    {
        /* On a Write, send new client config value to the app */
        MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_WRITE_CLIENT_CONFIG_IND);
        message->battery_server = battery_server;
        message->cid = access_ind->btConnId;
        message->config_value = (access_ind->writeUnit[0].value[0] & 0xFF) | ((access_ind->writeUnit[0].value[1] << 8) & 0xFF00);
        BasMessageSend(battery_server->app_task, GATT_BATTERY_SERVER_WRITE_CLIENT_CONFIG_IND, message);

        CsrBtGattDbWriteAccessResSend(battery_server->gattId,
                                      access_ind->btConnId,
                                      access_ind->attrHandle,
                                      CSR_BT_GATT_ACCESS_RES_SUCCESS);
    }
    else
    {
        sendBatteryWriteAccessErrorRsp(battery_server, access_ind, CSR_BT_GATT_ACCESS_RES_INVALID_LENGTH);
    }
}

/***************************************************************************
NAME
    batteryClientConfigReadAccess

DESCRIPTION
    Deals with access of the HANDLE_BATTERY_LEVEL_CLIENT_CONFIG handle.
*/
static void batteryClientConfigReadAccess(GBASS* battery_server, const CsrBtGattDbAccessReadInd* access_ind)
{
    /* On a Read, ask the app for current client config value */
    MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_READ_CLIENT_CONFIG_IND);
    message->battery_server = battery_server;     /* Pass the instance which can be returned in the response */
    message->cid = access_ind->btConnId;                 /* Pass the CID so the client can be identified */
    BasMessageSend(battery_server->app_task, GATT_BATTERY_SERVER_READ_CLIENT_CONFIG_IND, message);
}

/***************************************************************************
NAME
    batteryPresentationAccess

DESCRIPTION
    Deals with access of the HANDLE_BATTERY_LEVEL_PRESENTATION handle.
*/
static void batteryPresentationReadAccess(GBASS* battery_server, const CsrBtGattDbAccessReadInd* access_ind)
{
    /* Send read level message to app_task so it can return the current level */
    MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_READ_PRESENTATION_IND);
    message->battery_server = battery_server;     /* Pass the instance which can be returned in the response */
    message->cid = access_ind->btConnId;                 /* Pass the CID which can be returned in the response */
    BasMessageSend(battery_server->app_task, GATT_BATTERY_SERVER_READ_PRESENTATION_IND, message);
}

/***************************************************************************/
void handleBatteryServerWriteAccess(GBASS* battery_server, const CsrBtGattDbAccessWriteInd* access_ind)
{
    uint16 handle = access_ind->attrHandle;
#ifndef CSR_BT_GATT_INSTALL_FLAT_DB
    handle -= battery_server->start_handle;
#endif
    switch (handle)
    {
    case HANDLE_BATTERY_LEVEL_CLIENT_CONFIG:
        if (battery_server->notifications_enabled)
        {
            batteryClientConfigWriteAccess(battery_server, access_ind);
        }
        else
        {
            /* Handle shouldn't be accessed if notifications disabled */
            sendBatteryWriteAccessErrorRsp(battery_server, access_ind, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
        }
        break;
    default:
        /* Respond to invalid handles */
        sendBatteryWriteAccessErrorRsp(battery_server, access_ind, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
        break;
    }
}

/***************************************************************************/
void handleBatteryServerReadAccess(GBASS* battery_server, const CsrBtGattDbAccessReadInd* access_ind)
{
    uint16 handle = access_ind->attrHandle;
#ifndef CSR_BT_GATT_INSTALL_FLAT_DB
    handle -= battery_server->start_handle;
#endif
    switch (handle)
    {
    case HANDLE_BATTERY_LEVEL:
    {
        batteryLevelReadAccess(battery_server, access_ind);
    }
    break;

    case HANDLE_BATTERY_LEVEL_CLIENT_CONFIG:
    {
        if (battery_server->notifications_enabled)
        {
            batteryClientConfigReadAccess(battery_server, access_ind);
        }
        else
        {
            /* Handle shouldn't be accessed if notifications disabled */
            sendBatteryReadAccessErrorRsp(battery_server, access_ind, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
        }
    }
    break;

    case HANDLE_BATTERY_LEVEL_PRESENTATION:
    {
        batteryPresentationReadAccess(battery_server, access_ind);
    }
    break;

    default:
    {
        /* Respond to invalid handles */
        sendBatteryReadAccessErrorRsp(battery_server, access_ind, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
    }
    break;
    }
}

/***************************************************************************/
void sendBatteryConfigAccessRsp(const GBASS* battery_server, uint32 cid, uint16 client_config)
{
    uint8 config_resp[GATT_CLIENT_CONFIG_OCTET_SIZE];
    uint8* value = NULL;

    config_resp[0] = client_config & 0xFF;
    config_resp[1] = (client_config >> 8) & 0xFF;

    value = (uint8*)CsrPmemAlloc(GATT_CLIENT_CONFIG_OCTET_SIZE);
    memcpy(value, config_resp, GATT_CLIENT_CONFIG_OCTET_SIZE);
    sendBatteryAccessRsp(battery_server->gattId, cid, HANDLE_BATTERY_LEVEL_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
}

/***************************************************************************/
void sendBatteryPresentationAccessRsp(const GBASS* battery_server, uint32 cid, uint8 name_space, uint16 description)
{
    uint8 presentation[GATT_PRESENTATION_OCTET_SIZE];
    uint8* value = NULL;

    /* Fill in Presentation Attribute Value */
    /* Format - 1 octet */
    presentation[0] = 0x04; /* unsigned 8-bit integer */
    /* Exponent - 1 octet */
    presentation[1] = 0; /* actual value = characteristic value */
    /* Unit - 2 octets */
    presentation[2] = 0xAD; /* % lower 8-bits */
    presentation[3] = 0x27; /* % upper 8-bits */
    /* Name Space - 1 octet */
    presentation[4] = name_space;
    /* Description - 2 octets */
    presentation[5] = description & 0xFF;
    presentation[6] = (description >> 8) & 0xFF;
    /* Send complete presentation response */

    value = (uint8*)CsrPmemAlloc(GATT_PRESENTATION_OCTET_SIZE);
    memcpy(value, presentation, GATT_PRESENTATION_OCTET_SIZE);
    sendBatteryAccessRsp(battery_server->gattId, cid, HANDLE_BATTERY_LEVEL_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
}

#else /* EXCLUDE_GATT_BATTERY_SERVICE_V1P1 */

/***************************************************************************/
void sendBatteryConfigAccessRsp(const GBASS* batteryServer, uint32 cid, BasPrim primType, uint16 clientConfig)
{
    uint8 configResp[GATT_CLIENT_CONFIG_OCTET_SIZE];
    uint8* value = NULL;
    configResp[0] = clientConfig & 0xFF;
    configResp[1] = (clientConfig >> 8) & 0xFF;
    value = (uint8*)CsrPmemAlloc(GATT_CLIENT_CONFIG_OCTET_SIZE);
    SynMemCpyS(value,GATT_CLIENT_CONFIG_OCTET_SIZE, &configResp, GATT_CLIENT_CONFIG_OCTET_SIZE);

    switch (primType)
    {
        case GATT_BATTERY_SERVER_READ_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_LEVEL_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_BATTERY_LEVEL_STATUS_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_LEVEL_STATUS_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_BATTERY_LEVEL_STATUS_SERVER_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_LEVEL_STATUS_SERVER_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_SERVER_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_ESTIMATED_SERVICE_DATE_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_ESTIMATED_SERVICE_DATE_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_BATTERY_CRITICAL_STATUS_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_CRITICAL_STATUS_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_BATTERY_ENERGY_STATUS_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_ENERGY_STATUS_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_BATTERY_TIME_STATUS_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_TIME_STATUS_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_STATUS_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_HEALTH_STATUS_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_INFORMATION_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_HEALTH_INFORMATION_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_BATTERY_INFORMATION_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_INFORMATION_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_MANUFACTURER_NAME_STRING_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_MANUFACTURER_NAME_STRING_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_MODEL_NUMBER_STRING_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_MODEL_NUMBER_STRING_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        case GATT_BATTERY_SERVER_READ_SERIAL_NUMBER_CLIENT_CONFIG_IND:
        {
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_SERIAL_NUMBER_STRING_CLIENT_CONFIG, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_CLIENT_CONFIG_OCTET_SIZE, value);
            break;
        }
        default:
        {
            CSR_LOG_TEXT_ERROR((CsrBtGattLto, 0, "Invalid prim type"));
			break;
        }
    }
}

/***************************************************************************/
void sendBatteryPresentationAccessRsp(const GBASS* batteryServer, uint32 cid, BasPrim primType, uint8 nameSpace, uint16 description)
{
    uint8 presentation[GATT_PRESENTATION_OCTET_SIZE];
    uint8* value = NULL;

    presentation[1] = 0;    /* Exponent - 1 octet */
    /* Name Space - 1 octet */
    presentation[4] = nameSpace;
    /* Description - 2 octets */
    presentation[5] = description & 0xFF;
    presentation[6] = (description >> 8) & 0xFF;
    value = (uint8*)CsrPmemAlloc(GATT_PRESENTATION_OCTET_SIZE);

    switch (primType)
    {
        case GATT_BATTERY_SERVER_READ_PRESENTATION_IND:
        {
            /* Format - 1 octet */
            presentation[0] = 0x04; /* unsigned 8-bit interger */
            presentation[2] = 0xAD; /* % lower 8-bits */
            presentation[3] = 0x27; /* % upper 8-bits */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_LEVEL_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_ESTIMATED_SERVICE_DATE_PRESENTATION_IND:
        {
            /* Format - 1 octet */
            presentation[0] = 0x07; /* unsigned 24-bit integer */
            /* Unit - 2 octets */
            presentation[2] = 0xED; /* Date UTC lower 8-bits */
            presentation[3] = 0x2A; /* Date UTC upper 8-bits */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_ESTIMATED_SERVICE_DATE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_EXTERNAL_SOURCE_POWER_PRESENTATION_IND:
        {
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bit */
            /* Unit - 2 octets */
            presentation[2] = 0x26; /* Watt lower 8-bits */
            presentation[3] = 0x27; /* Watt upper 8-bits */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_EXTERNAL_SOURCE_POWER_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_PRESENT_VOLTAGE_PRESENTATION_IND:
        {
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bit */
            /* Unit - 2 octets */
            presentation[2] = 0x18; /* voltage lower 8-bits */
            presentation[3] = 0x2B; /* voltage upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_PRESENT_VOLTAGE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_AVAILABLE_ENERGY_PRESENTATION_IND:
        {
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bits */
            /* Unit - 2 octets */
            presentation[2] = 0xAB; /* kilowatt_hr lower 8-bits */
            presentation[3] = 0x27; /* kilowatt_hr upper 8-bits */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_AVAILABLE_ENERGY_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_AVAILABLE_BATTERY_CAPACITY_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bits */
            /* Unit - 2 octets */
            presentation[2] = 0xAB; /* kilowatt_hr lower 8-bits */
            presentation[3] = 0x27; /* kilowatt_hr upper 8-bits */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_AVAILABLE_BATTERY_CAPACITY_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_CHARGE_RATE_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bits */
            /* Unit - 2 octets */
            presentation[2] = 0x26; /* watt lower 8-bits */
            presentation[3] = 0x27; /* watt upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_CHARGE_RATE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_AVAILABLE_ENERGY_AT_LAST_CHARGE_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bits */
            /* Unit - 2 octets */
            presentation[2] = 0xAB; /* kilowatt_hr lower 8-bits */
            presentation[3] = 0x27; /* kilowatt_hr upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_AVAILABLE_ENERGY_AT_LAST_CHARGE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_BATTERY_TIME_STATUS_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x07; /* unsigned 24-bit integer */
            /* Unit - 2 octets */
            presentation[2] = 0x60; /* minutes lower 8-bits */
            presentation[3] = 0x27; /* minutes upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_TIME_STATUS_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_SUMMARY_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x04; /* unsigned 8-bit integer */
            /* Unit - 2 octets */
            presentation[2] = 0xAD; /* % lower 8-bits */
            presentation[3] = 0x27; /* % upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_HEALTH_SUMMARY_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_CURRENT_TEMPERATURE_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x0C; /* signed 8-bit integer */
            /* Unit - 2 octets */
            presentation[2] = 0x2F; /* degree_celcius lower 8-bits */
            presentation[3] = 0x27; /* % upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_CURRENT_TEMPERATURE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);

        }
        break;
        case GATT_BATTERY_SERVER_READ_MIN_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x0C; /* signed 8-bit integer */
            /* Unit - 2 octets */
            presentation[2] = 0x2F; /* degree_celcius lower 8-bits */
            presentation[3] = 0x27; /* degree_celcius upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_MIN_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_MAX_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x0C; /* signed 8-bit integer */
            /* Unit - 2 octets */
            presentation[2] = 0x2F; /* degree_celcius lower 8-bits */
            presentation[3] = 0x27; /* degree_celcius upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_MAX_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_BATTERY_MANUFACTURE_DATE_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x07; /* unsigned 24-bit integer */
            /* Unit - 2 octets */
            presentation[2] = 0x62; /* time.day lower 8-bits */
            presentation[3] = 0x27; /* time.day upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_MANUFACTURE_DATE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_BATTERY_EXPIRATION_DATE_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x07; /* unsigned 24-bit integer */
            /* Unit - 2 octets */
            presentation[2] = 0x62; /* time.day lower 8-bits */
            presentation[3] = 0x27; /* time.day upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_EXPIRATION_DATE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_BATTERY_DESIGNED_CAPACITY_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bit */
            /* Unit - 2 octets */
            presentation[2] = 0xAB; /* kilowatt_hr lower 8-bits */
            presentation[3] = 0x27; /* kilowatt_hr upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_DESIGNED_CAPACITY_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_BATTERY_LOW_ENERGY_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bit */
            /* Unit - 2 octets */
            presentation[2] = 0xAB; /* kilowatt_hr lower 8-bits */
            presentation[3] = 0x27; /* kilowatt_hr upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_LOW_ENERGY_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_BATTERY_CRITICAL_ENERGY_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x16; /* medfloat 16-bit */
            /* Unit - 2 octets */
            presentation[2] = 0xAB; /* kilowatt_hr lower 8-bits */
            presentation[3] = 0x27; /* kilowatt_hr upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_CRITICAL_ENERGY_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_NOMINAL_VOLTAGE_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x16; /*  medfloat 16-bit */
            /* Exponent - 1 octet */
            presentation[1] = 0; /* actual value = characteristic value */
            /* Unit - 2 octets */
            presentation[2] = 0x28; /* volt lower 8-bits */
            presentation[3] = 0x27; /* volt upper 8-bits */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_NOMINAL_VOLTAGE_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_MANUFACTURER_NAME_STRING_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x19; /* UTF-8 string */
            /* Unit - 2 octets */
            presentation[2] = 0x00; /* unitless */
            presentation[3] = 0x27; /* unitless */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_MANUFACTURER_NAME_STRING_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_MODEL_NUMBER_STRING_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x19; /* UTF-8 string */
            /* Unit - 2 octets */
            presentation[2] = 0x00; /* % unitless */
            presentation[3] = 0x27; /* % unitless */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_MODEL_NUMBER_STRING_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
        case GATT_BATTERY_SERVER_READ_SERIAL_NUMBER_PRESENTATION_IND:
        {
            /* Fill in Presentation Attribute Value */
            /* Format - 1 octet */
            presentation[0] = 0x19; /* UTF8 string */
            /* Exponent - 1 octet */
            presentation[1] = 0; /* actual value = characteristic value */
            /* Unit - 2 octets */
            presentation[2] = 0x00; /* % unitless */
            presentation[3] = 0x00; /* % unitless */
            /* Send complete presentation response */
            SynMemCpyS(value, GATT_PRESENTATION_OCTET_SIZE, presentation, GATT_PRESENTATION_OCTET_SIZE);
            sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_SERIAL_NUMBER_STRING_PRESENTATION, CSR_BT_GATT_ACCESS_RES_SUCCESS, GATT_PRESENTATION_OCTET_SIZE, value);
        }
        break;
    }
}

/***************************************************************************/
void handleBatteryServerSendCfmEvent(GBASS* batteryServer, const CsrBtGattEventSendCfm* accessInd)
{
    MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_SEND_CFM_EVENT_IND);
    message->battery_server = batteryServer;
    message->cid = accessInd->btConnId;
    BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_SEND_CFM_EVENT_IND, message);
}

/***************************************************************************/
void sendBatteryLevelStatusAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryLevelStatus batteryLevelStatus, uint16 result)
{
    uint8* value = (uint8*)CsrPmemAlloc(GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE);
    uint8* octate = value;
    uint8 size = 3;
    SynMemCpyS(octate, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.flags, GATT_BATTERY_FLAGS_SIZE);
    octate += GATT_BATTERY_FLAGS_SIZE;
    SynMemCpyS(octate, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.powerState, GATT_BATTERY_LEVEL_STATUS_POWER_STATE_SIZE);
    octate += GATT_BATTERY_LEVEL_STATUS_POWER_STATE_SIZE;
    if (batteryLevelStatus.flags & IDENTIFIER_PRESENT)
    {
        SynMemCpyS(octate, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.identifier, GATT_BATTERY_LEVEL_STATUS_IDENTIFIER_OCTET_SIZE);
        octate += GATT_BATTERY_LEVEL_STATUS_IDENTIFIER_OCTET_SIZE;
        size += GATT_BATTERY_LEVEL_STATUS_IDENTIFIER_OCTET_SIZE;
    }
    if (batteryLevelStatus.flags & BATTERY_LEVEL_PRESENT)
    {
        SynMemCpyS(octate, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.batteryLevel, GATT_BATTERY_LEVEL_OCTET_SIZE);
        octate += GATT_BATTERY_LEVEL_OCTET_SIZE;
        size += GATT_BATTERY_LEVEL_OCTET_SIZE;
    }
    if (batteryLevelStatus.flags & ADDITIONAL_STATUS_PRESENT)
    {
        SynMemCpyS(octate, GATT_BATTERY_LEVEL_STATUS_OCTET_SIZE, &batteryLevelStatus.additionalStatus, GATT_BATTERY_LEVEL_STATUS_ADDITIONAL_STATUS_OCTET_SIZE);
        octate += GATT_BATTERY_LEVEL_STATUS_ADDITIONAL_STATUS_OCTET_SIZE;
        size += GATT_BATTERY_LEVEL_STATUS_ADDITIONAL_STATUS_OCTET_SIZE;
    }
    octate = NULL;
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_LEVEL_STATUS, result, size, value);
}

/***************************************************************************/
void sendBatteryEstimatedServiceDateAccessRsp(const GBASS* batteryServer, uint32 cid, uint32 estimatedServiceDate, uint16 result)
{
    uint8* value = (uint8*)CsrPmemAlloc(GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE);
    SynMemCpyS(value, GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE, &estimatedServiceDate, GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE);
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_ESTIMATED_SERVICE_DATE, result, GATT_ESTIMATED_SERVICE_DATE_OCTET_SIZE, value);
}

/***************************************************************************/
void sendBatteryCriticalStatusAccessRsp(const GBASS* batteryServer, uint32 cid, uint8 batteryCriticalStatus, uint16 result)
{
    uint8* value = (uint8*)CsrPmemAlloc(GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE);
    SynMemCpyS(value, GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE, &batteryCriticalStatus, GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE);
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_CRITICAL_STATUS, result, GATT_BATTERY_CRITICAL_STATUS_OCTET_SIZE, value);
}

/***************************************************************************/
void sendBatteryEnergyStatusAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryEnergyStatus batteryEnergyStatus, uint16 result)
{
    uint8* value = (uint8*)CsrPmemAlloc(GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE);
    uint8* octate = value;
    uint16 size = 1;
    SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus, GATT_BATTERY_FLAGS_SIZE);
    octate += GATT_BATTERY_FLAGS_SIZE;
    if (batteryEnergyStatus.flags & EXTERNAL_SOURCE_POWER_PRESENT) {
        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.externalSourcePower, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
    }
    if (batteryEnergyStatus.flags & PRESENT_VOLTAGE_PRESENT) {
        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.presentVoltage, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
    }
    if (batteryEnergyStatus.flags & AVAILABLE_ENERGY_PRESENT) {
        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.availableEnergy, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
    }
    if (batteryEnergyStatus.flags & AVAILABLE_BATTERY_CAPACITY_PRESENT) {
        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.availableBatteryCapacity, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
    }
    if (batteryEnergyStatus.flags & CHARGE_RATE_PRESENT) {
        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.chargeRate, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
    }
    if (batteryEnergyStatus.flags & AVAILABLE_ENERGY_AT_LAST_CHARGE_PRESENT) {
        SynMemCpyS(octate, GATT_BATTERY_ENERGY_STATUS_OCTET_SIZE, &batteryEnergyStatus.availableEnergyAtLastCharge, GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE);
        octate += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
        size += GATT_BATTERY_ENERGY_STATUS_FIELDS_OCTET_SIZE;
    }
    octate = NULL;
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_ENERGY_STATUS, result, size, value);
}

/***************************************************************************/
void sendBatteryTimeStatusAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryTimeStatus currentBatteryTimeStatus, uint16 result)
{
    /*
        The battery time status inclued the the bit masking flags(mandatory) - 1 octet,
        Estimated time in minutes until discharged(mandatory) - 3 octets,
        Estimated time in minutes until discharged assuming for the remaining time the device is in standby(present if bit 0 of flags is set to 1) - 0 or 3 octets,
        Estimated time in minutes until recharged(present if bit 1 of flags is set to 1) - 0 or 3 octets.
    */
    GattBatteryTimeStatus* value = (GattBatteryTimeStatus*)CsrPmemAlloc(sizeof(GattBatteryTimeStatus));
    uint8* temp = (uint8*)value, sizeValue = 4;
	uint8 i = sizeValue, * temp1 = (uint8*)value;
    SynMemCpyS(temp, sizeof(GattBatteryTimeStatus), &currentBatteryTimeStatus.batteryTimeStatusFlags, sizeof(uint8));
    temp++;
    SynMemCpyS(temp, sizeof(GattBatteryTimeStatus), &currentBatteryTimeStatus.timeUntilDischarged, 3 * sizeof(uint8));
    temp += 3;
    if (currentBatteryTimeStatus.batteryTimeStatusFlags & TIME_UNTIL_DISCHARGED_ON_STANDBY_PRESENT) {
        sizeValue += 3;
        SynMemCpyS(temp, sizeof(GattBatteryTimeStatus), &currentBatteryTimeStatus.timeUntilDischargedOnStandby, 3 * sizeof(uint8));
        temp += 3;
    }
    if (currentBatteryTimeStatus.batteryTimeStatusFlags & TIME_UNTIL_RECHARGED_PRESENT) {
        sizeValue += 3;
        SynMemCpyS(temp, sizeof(GattBatteryTimeStatus), &currentBatteryTimeStatus.timeUntilRecharged, 3 * sizeof(uint8));
        temp += 3;
    }
    while (i > 0) {
        temp1++;
        i--;
    }
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_TIME_STATUS, result, sizeValue, (uint8*)value);
}

/***************************************************************************/
void sendBatteryHealthStatusAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryHealthStatus batteryHealthStatus, uint16 result)
{
    /*
        The battery health status inclued the the bit masking flags(mandatory) - 1 octet,
        Battery health summary(present if bit 0 of flags is set to 1) - 0 or 1 octet,
        Cycle count(present if bit 1 of flags is set to 1) - 0 or 2 octets,
        Current temperature(present if bit 2 of flags is set to 1) - 0 or 1 octet,
        Deep discharge count(present if bit 3 of flags is set to 1) - 0 or 2 octets.
    */
    GattBatteryHealthStatus* value = (GattBatteryHealthStatus*)CsrPmemAlloc(sizeof(GattBatteryHealthStatus));
    uint8* temp = (uint8*)value, sizeValue = 1;
    SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.batteryHealthStatusFlags, sizeof(uint8)); 
    temp += 1;
    if (batteryHealthStatus.batteryHealthStatusFlags & BATTERY_HEALTH_SUMMARY_PRESENT) {
        sizeValue += 1;
        SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.batteryHealthSummary, sizeof(uint8)); 
        temp += 1;
    }
    if (batteryHealthStatus.batteryHealthStatusFlags & CYCLE_COUNT_PRESENT) {
        sizeValue += 2;
        SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.cycleCount, sizeof(uint16)); 
        temp += 2;
    }
    if (batteryHealthStatus.batteryHealthStatusFlags & CURRENT_TEMPERATURE_PRESENT) {
        sizeValue += 1;
        SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.currentTemperature, sizeof(int8)); 
        temp += 1;
    }
    if (batteryHealthStatus.batteryHealthStatusFlags & DEEP_DISCHARGE_COUNT_PRESENT) {
        sizeValue += 2;
        SynMemCpyS(temp, sizeof(GattBatteryHealthStatus), &batteryHealthStatus.deepDischargeCount, sizeof(uint16)); 
        temp += 2;
    }
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_HEALTH_STATUS, result, sizeValue, (uint8*)value);
}

/***************************************************************************/
void sendBatteryHealthInformationAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryHealthInformation batteryHealthInformation, uint16 result)
{
    /*
        The battery health information inclued the the bit masking flags(mandatory) - 1 octet,
        Cycle count designed lifetime(present if bit 0 of flags is set to 1) - 0 or 2 octets,
        Min designed operating temperature(present if bit 1 of flags is set to 1) - 0 or 1 octet,
        Max designed operating temperature(present if bit 1 of flags is set to 1) - 0 or 1 octet.
    */
    GattBatteryHealthInformation* value = (GattBatteryHealthInformation*)CsrPmemAlloc(sizeof(GattBatteryHealthInformation));
    uint8* temp = (uint8*)value, sizeValue = 1;
    SynMemCpyS(temp, sizeof(GattBatteryHealthInformation), &batteryHealthInformation.batteryHealthInformationFlags, sizeof(uint8)); 
    temp += 1;
    if (batteryHealthInformation.batteryHealthInformationFlags & CYCLE_COUNT_DESIGNED_LIFETIME_PRESENT) {
        sizeValue += 2;
        SynMemCpyS(temp, sizeof(GattBatteryHealthInformation), &batteryHealthInformation.cycleCountDesignedLifetime, 2 * sizeof(uint8)); 
        temp += 2;
    }
    if (batteryHealthInformation.batteryHealthInformationFlags & MIN_AND_MAX_OPERATING_TEMPERATURE_PRESENT) {
        sizeValue += 1;
        SynMemCpyS(temp, sizeof(GattBatteryHealthInformation), &batteryHealthInformation.minDesignedOperatingTemperature, sizeof(uint8)); 
        temp += 1;
        sizeValue += 1;
        SynMemCpyS(temp, sizeof(GattBatteryHealthInformation), &batteryHealthInformation.maxDesignedOperatingTemperature, sizeof(uint8)); 
        temp += 1;
    }
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_HEALTH_INFORMATION, result, sizeValue, (uint8*)value);
}

/***************************************************************************/
void sendBatteryInformationAccessRsp(const GBASS* batteryServer, uint32 cid, GattBatteryInformation batteryInformation, uint16 result)
{
    /*
        The battery information inclued the the bit masking flags(mandatory) - 1 octet,
        Battery features(mandatory) - 1 octet,
        Battery manufacture date(present if bit 0 of flags is set to 1) - 0 or 3 octets,
        Battery expiration date(present if bit 1 of flags is set to 1) - 0 or 3 octets,
        Battery designed capacity(present if bit 2 of flags is set to 1) - 0 or 2 octets,
        Battery low energy(present if bit 3 of flags is set to 1) - 0 or 2 octets,
        Battery critical energy(present if bit 4 of flags is set to 1) - 0 or 2 octets,
        Battery chemistry(present if bit 5 of flags is set to 1) - 0 or 1 octet1,
        Nominal voltage(present if bit 6 of flags is set to 1) - 0 or 2 octets,
        Battery aggregation group(present if bit 7 of flags is set to 1) - 0 or 1 octet.
    */
    GattBatteryInformation* value = (GattBatteryInformation*)CsrPmemAlloc(sizeof(GattBatteryInformation));
    uint8* temp = (uint8*)value, sizeValue = 2;
    SynMemCpyS(temp,sizeof(GattBatteryInformation), &batteryInformation.batteryInformationFlags, sizeof(uint16));
    temp += 2;
    SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryFeatures, sizeof(uint8)); sizeValue += 1;
    temp += 1;
    if (batteryInformation.batteryInformationFlags & BATTERY_MANUFACTURE_DATE_PRESENT) {
        sizeValue += 3;
        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryManufactureDate, 3 * sizeof(uint8));
        temp += 3;
    }
    if (batteryInformation.batteryInformationFlags & BATTERY_EXPIRATION_DATE_PRESENT) {
        sizeValue += 3;
        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryExpirationDate, 3 * sizeof(uint8));
        temp += 3;
    }
    if (batteryInformation.batteryInformationFlags & BATTERY_DESIGNED_CAPACITY_PRESENT) {
        sizeValue += 2;
        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryDesignedCapacity, 2 * sizeof(uint8));
        temp += 2;
    }
    if (batteryInformation.batteryInformationFlags & BATTERY_LOW_ENERGY_PRESENT) {
        sizeValue += 2;
        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryLowEnergy, 2 * sizeof(uint8));
        temp += 2;
    }
    if (batteryInformation.batteryInformationFlags & BATTERY_CRTICAL_ENERGY_PRESENT) {
        sizeValue += 2;
        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryCriticalEnergy, 2 * sizeof(uint8));
        temp += 2;
    }
    if (batteryInformation.batteryInformationFlags & BATTERY_CHEMISTRY_PRESENT) {
        sizeValue += 1;
        SynMemCpyS(temp, sizeof(GattBatteryInformation) , &batteryInformation.batteryChemistry, sizeof(uint8));
        temp += 1;
    }
    if (batteryInformation.batteryInformationFlags & NOMINAL_VOLTAGE_PRESENT) {
        sizeValue += 2;
        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.nominalVoltage, 2 * sizeof(uint8));
        temp += 2;
    }
    if (batteryInformation.batteryInformationFlags & BATTERY_AGGREGATION_GROUP_PRESENT) {
        sizeValue += 1;
        SynMemCpyS(temp, sizeof(GattBatteryInformation), &batteryInformation.batteryAggregationGroup, sizeof(uint8));
        temp += 1;
    }
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_BATTERY_INFORMATION, result, sizeValue, (uint8*)value);
}

/***************************************************************************/
void sendManufacturerNameStringAccessRsp(const GBASS* batteryServer, uint32 cid, uint8* manufacturerNameString, uint16 result)
{
    uint8* value = (uint8*)CsrPmemAlloc(100 * sizeof(uint8));
    uint8* temp = value, sizeValue = 0;
    while (*manufacturerNameString != '\0') {
        SynMemCpyS(temp, 100, manufacturerNameString, sizeof(uint8));
        //printf("%c", *temp);
        manufacturerNameString++;
        temp++;
        sizeValue++;
    }
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_MANUFACTURER_NAME_STRING, result, sizeValue, value);
}

/***************************************************************************/
void sendModelNumberStringAccessRsp(const GBASS* batteryServer, uint32 cid, uint8* modelNumberString, uint16 result)
{
    uint8* value = (uint8*)CsrPmemAlloc(100 * sizeof(uint8));
    uint8* temp = value, sizeValue = 0;
    while (*modelNumberString != '\0') {
        SynMemCpyS(temp, 100, modelNumberString, sizeof(uint8));
        //printf("%c", *temp);
        modelNumberString++;
        temp++;
        sizeValue++;
    }
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_MODEL_NUMBER_STRING, result, sizeValue, value);
}

/***************************************************************************/
void sendBatterySerialNumberAccessRsp(const GBASS* batteryServer, uint32 cid, uint8* serialNumber, uint16 size, uint16 result)
{
    uint8* value = (uint8*)CsrPmemAlloc(size);
    SynMemCpyS(value, size, serialNumber, size);
    sendBatteryAccessRsp(batteryServer->gattId, cid, HANDLE_SERIAL_NUMBER_STRING, result, size, value);
}

/***************************************************************************/
void batteryReadAccess(GBASS* batteryServer, const CsrBtGattDbAccessReadInd* accessInd)
{
    MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_READ_IND);
    message->battery_server = batteryServer;     /* Pass the instance which can be returned in the response */
    message->cid = accessInd->btConnId;                 /* Pass the CID which can be returned in the response */
    switch (accessInd->attrHandle)
    {
    case HANDLE_BATTERY_LEVEL:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_LEVEL_IND, message);
    }
    break;
    case HANDLE_BATTERY_LEVEL_STATUS:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_LEVEL_STATUS_IND, message);
    }
    break;
    case HANDLE_ESTIMATED_SERVICE_DATE:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_ESTIMATED_SERVICE_DATE_IND, message);
    }
    break;
    case HANDLE_BATTERY_CRITICAL_STATUS:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_CRITICAL_STATUS_IND, message);
    }
    break;
    case HANDLE_BATTERY_ENERGY_STATUS:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_ENERGY_STATUS_IND, message);
    }
    break;
    case HANDLE_BATTERY_TIME_STATUS:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_TIME_STATUS_IND, message);
    }
    break;
    case HANDLE_BATTERY_HEALTH_STATUS:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_STATUS_IND, message);
    }
    break;
    case HANDLE_BATTERY_HEALTH_INFORMATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_INFORMATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_INFORMATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_INFORMATION_IND, message);
    }
    break;
    case HANDLE_MANUFACTURER_NAME_STRING:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MANUFACTURER_NAME_STRING_IND, message);
    }
    break;
    case HANDLE_MODEL_NUMBER_STRING:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MODEL_NUMBER_STRING_IND, message);
    }
    break;
    case HANDLE_SERIAL_NUMBER_STRING:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_SERIAL_NUMBER_STRING_IND, message);
    }
    break;
    default:
    {
        sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_RESULT_INVALID_HANDLE_RANGE);
    }
    }
}

/***************************************************************************
NAME
    BatteryClientConfigWriteAccess

DESCRIPTION
    Deals with write access of the config handle .
*/
static void batteryClientConfigWriteAccess(GBASS* batteryServer, const CsrBtGattDbAccessWriteInd* accessInd)
{
    if (accessInd->writeUnit[0].valueLength == GATT_CLIENT_CONFIG_OCTET_SIZE)
    {
        MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_WRITE_CLIENT_CONFIG_IND);
        message->battery_server = batteryServer;
        message->cid = accessInd->btConnId;
        message->config_value = (accessInd->writeUnit[0].value[0] & 0xFF) | ((accessInd->writeUnit[0].value[1] << 8) & 0xFF00);

        /* On a Write, send new client config value to the app */
        switch (accessInd->attrHandle) {
        case HANDLE_BATTERY_LEVEL_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_BATTERY_LEVEL_STATUS_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_BATTERY_LEVEL_STATUS_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_BATTERY_LEVEL_STATUS_SERVER_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_BATTERY_LEVEL_STATUS_SERVER_CONFIG_IND, message);
        }
        break;
        case HANDLE_ESTIMATED_SERVICE_DATE_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_ESTIMATED_SERVICE_DATE_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_BATTERY_CRITICAL_STATUS_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_BATTERY_CRITICAL_STATUS_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_BATTERY_ENERGY_STATUS_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_BATTERY_ENERGY_STATUS_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_BATTERY_TIME_STATUS_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_BATTERY_TIME_STATUS_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_BATTERY_HEALTH_STATUS_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_BATTERY_HEALTH_STATUS_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_BATTERY_HEALTH_INFORMATION_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_BATTERY_HEALTH_INFORMATION_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_BATTERY_INFORMATION_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_BATTERY_INFORMATION_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_MANUFACTURER_NAME_STRING_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_MANUFACTURER_NAME_STRING_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_MODEL_NUMBER_STRING_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_MODEL_NUMBER_STRING_CLIENT_CONFIG_IND, message);
        }
        break;
        case HANDLE_SERIAL_NUMBER_STRING_CLIENT_CONFIG:
        {
            BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_WRITE_SERIAL_NUMBER_CLIENT_CONFIG_IND, message);
        }
        break;
        default:
        {
            sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_RESULT_INVALID_HANDLE_RANGE);
        }
        }
        CsrBtGattDbWriteAccessResSend(batteryServer->gattId,
            accessInd->btConnId,
            accessInd->attrHandle,
            CSR_BT_GATT_ACCESS_RES_SUCCESS);
    }
    else
    {
        sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_LENGTH);
    }
}

/***************************************************************************
NAME
    batteryClientConfigReadAccess

DESCRIPTION
*/
static void batteryClientConfigReadAccess(GBASS* batteryServer, const CsrBtGattDbAccessReadInd* accessInd)
{
    /* On a Read, ask the app for current client config value */
    MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_READ_CLIENT_CONFIG_IND);
    message->battery_server = batteryServer;     /* Pass the instance which can be returned in the response */
    message->cid = accessInd->btConnId;                 /* Pass the CID so the client can be identified */
    switch (accessInd->attrHandle) {
    case HANDLE_BATTERY_LEVEL_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_BATTERY_LEVEL_STATUS_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_LEVEL_STATUS_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_BATTERY_LEVEL_STATUS_SERVER_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_LEVEL_STATUS_SERVER_CONFIG_IND, message);
    }
    break;
    case HANDLE_ESTIMATED_SERVICE_DATE_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_ESTIMATED_SERVICE_DATE_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_BATTERY_CRITICAL_STATUS_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_CRITICAL_STATUS_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_BATTERY_ENERGY_STATUS_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_ENERGY_STATUS_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_BATTERY_TIME_STATUS_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_TIME_STATUS_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_BATTERY_HEALTH_STATUS_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_STATUS_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_BATTERY_HEALTH_INFORMATION_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_INFORMATION_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_BATTERY_INFORMATION_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_INFORMATION_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_MANUFACTURER_NAME_STRING_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MANUFACTURER_NAME_STRING_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_MODEL_NUMBER_STRING_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MODEL_NUMBER_STRING_CLIENT_CONFIG_IND, message);
    }
    break;
    case HANDLE_SERIAL_NUMBER_STRING_CLIENT_CONFIG:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_SERIAL_NUMBER_CLIENT_CONFIG_IND, message);
    }
    break;
    default:
    {
        sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_RESULT_INVALID_HANDLE_RANGE);
    }
    }
}

/***************************************************************************
NAME
    BatteryPresentationReadAccess

DESCRIPTION
    Deals with access of the HANDLE_BATTERY_LEVEL_PRESENTATION handle.
*/
static void batteryPresentationReadAccess(GBASS* batteryServer, const CsrBtGattDbAccessReadInd* accessInd)
{
    /* Send read level message to app_task so it can return the current level */
    MAKE_BATTERY_MESSAGE(GATT_BATTERY_SERVER_READ_PRESENTATION_IND);
    message->battery_server = batteryServer;     /* Pass the instance which can be returned in the response */
    message->cid = accessInd->btConnId;                 /* Pass the CID which can be returned in the response */

    switch (accessInd->attrHandle)
    {
    case HANDLE_BATTERY_LEVEL_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_ESTIMATED_SERVICE_DATE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_ESTIMATED_SERVICE_DATE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_EXTERNAL_SOURCE_POWER_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_EXTERNAL_SOURCE_POWER_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_PRESENT_VOLTAGE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_PRESENT_VOLTAGE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_AVAILABLE_ENERGY_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_AVAILABLE_ENERGY_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_AVAILABLE_BATTERY_CAPACITY_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_AVAILABLE_BATTERY_CAPACITY_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_CHARGE_RATE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_CHARGE_RATE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_AVAILABLE_ENERGY_AT_LAST_CHARGE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_AVAILABLE_ENERGY_AT_LAST_CHARGE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_ENERGY_STATUS_PRESENTATION_AGGREGATE:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_EXTERNAL_SOURCE_POWER_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_PRESENT_VOLTAGE_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_AVAILABLE_ENERGY_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_AVAILABLE_BATTERY_CAPACITY_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_CHARGE_RATE_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_AVAILABLE_ENERGY_AT_LAST_CHARGE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_TIME_STATUS_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_TIME_STATUS_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_HEALTH_SUMMARY_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_SUMMARY_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_CURRENT_TEMPERATURE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_CURRENT_TEMPERATURE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_HEALTH_STATUS_AGGREGATE:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_HEALTH_SUMMARY_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_CURRENT_TEMPERATURE_PRESENTATION_IND, message);
    }
    case HANDLE_MIN_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MIN_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_MAX_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MAX_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_HEALTH_INFORMATION_AGGREGATE:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MIN_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MAX_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_MANUFACTURE_DATE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_MANUFACTURE_DATE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_EXPIRATION_DATE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_EXPIRATION_DATE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_DESIGNED_CAPACITY_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_DESIGNED_CAPACITY_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_LOW_ENERGY_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_LOW_ENERGY_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_CRITICAL_ENERGY_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_CRITICAL_ENERGY_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_NOMINAL_VOLTAGE_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_NOMINAL_VOLTAGE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_BATTERY_INFORMATION_AGGREGATE:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_MANUFACTURE_DATE_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_EXPIRATION_DATE_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_DESIGNED_CAPACITY_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_LOW_ENERGY_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_BATTERY_CRITICAL_ENERGY_PRESENTATION_IND, message);
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_NOMINAL_VOLTAGE_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_MANUFACTURER_NAME_STRING_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MANUFACTURER_NAME_STRING_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_MODEL_NUMBER_STRING_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_MODEL_NUMBER_STRING_PRESENTATION_IND, message);
    }
    break;
    case HANDLE_SERIAL_NUMBER_STRING_PRESENTATION:
    {
        BasMessageSend(batteryServer->app_task, GATT_BATTERY_SERVER_READ_SERIAL_NUMBER_PRESENTATION_IND, message);
    }
    break;
    default:
    {
        sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_RESULT_INVALID_HANDLE_RANGE);
    }
    }
}

/***************************************************************************/
void handleBatteryServerWriteAccess(GBASS *batteryServer, const CsrBtGattDbAccessWriteInd *accessInd)
{
    uint16 handle = accessInd->attrHandle;

    switch (handle)
    {
        case HANDLE_BATTERY_LEVEL_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
	   case HANDLE_BATTERY_LEVEL_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
       case HANDLE_BATTERY_LEVEL_STATUS_SERVER_CONFIG:
       {
           if (batteryServer->broadcastEnabled)
           {
               batteryClientConfigWriteAccess(batteryServer, accessInd);
           }
           else
           {
               sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
           }
           break;
       }
        case HANDLE_ESTIMATED_SERVICE_DATE_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_BATTERY_CRITICAL_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_BATTERY_ENERGY_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_SERIAL_NUMBER_STRING_CLIENT_CONFIG:
        {
            if (batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_BATTERY_TIME_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_BATTERY_HEALTH_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_BATTERY_HEALTH_INFORMATION_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_BATTERY_INFORMATION_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_MANUFACTURER_NAME_STRING_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        case HANDLE_MODEL_NUMBER_STRING_CLIENT_CONFIG:
        {    
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigWriteAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
            break;
        }
        default:
            /* Respond to invalid handles */
            sendBatteryWriteAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
    }
}

/***************************************************************************/
void handleBatteryServerReadAccess(GBASS *batteryServer, const CsrBtGattDbAccessReadInd *accessInd)
 {
    uint16 handle = accessInd->attrHandle;

    switch (handle)
    {   
        case HANDLE_BATTERY_LEVEL:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_LEVEL_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled or indication disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_BATTERY_LEVEL_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_LEVEL_STATUS:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_LEVEL_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->indicationsEnabled || batteryServer->notifications_enabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled or indication disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_BATTERY_LEVEL_STATUS_SERVER_CONFIG:
        {
            if (batteryServer->broadcastEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled or indication disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_ESTIMATED_SERVICE_DATE:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_ESTIMATED_SERVICE_DATE_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notification or indication disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_ESTIMATED_SERVICE_DATE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_ENERGY_STATUS:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_ENERGY_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->indicationsEnabled || batteryServer->notifications_enabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_EXTERNAL_SOURCE_POWER_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_PRESENT_VOLTAGE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_AVAILABLE_ENERGY_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_AVAILABLE_BATTERY_CAPACITY_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_CHARGE_RATE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_AVAILABLE_ENERGY_AT_LAST_CHARGE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_CRITICAL_STATUS:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_CRITICAL_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_BATTERY_TIME_STATUS:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_TIME_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled) {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_BATTERY_TIME_STATUS_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_HEALTH_STATUS:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_HEALTH_STATUS_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_BATTERY_HEALTH_SUMMARY_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_CURRENT_TEMPERATURE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_HEALTH_STATUS_AGGREGATE:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_HEALTH_INFORMATION:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_HEALTH_INFORMATION_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_MIN_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_MAX_DESIGNED_OPERATING_TEMPERATURE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;        
        case HANDLE_BATTERY_HEALTH_INFORMATION_AGGREGATE:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_INFORMATION:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_INFORMATION_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_BATTERY_MANUFACTURE_DATE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_EXPIRATION_DATE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_DESIGNED_CAPACITY_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_LOW_ENERGY_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_BATTERY_CRITICAL_ENERGY_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_NOMINAL_VOLTAGE_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_MANUFACTURER_NAME_STRING:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_MANUFACTURER_NAME_STRING_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_MANUFACTURER_NAME_STRING_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_MODEL_NUMBER_STRING:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_MODEL_NUMBER_STRING_CLIENT_CONFIG:
        {
            if (batteryServer->notifications_enabled || batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                /* Handle shouldn't be accessed if notifications disabled */
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_MODEL_NUMBER_STRING_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_SERIAL_NUMBER_STRING:
        {
            batteryReadAccess(batteryServer, accessInd);
        }
        break;
        case HANDLE_SERIAL_NUMBER_STRING_CLIENT_CONFIG:
        {
            if (batteryServer->indicationsEnabled)
            {
                batteryClientConfigReadAccess(batteryServer, accessInd);
            }
            else
            {
                sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
            }
        }
        break;
        case HANDLE_SERIAL_NUMBER_STRING_PRESENTATION:
        {
            batteryPresentationReadAccess(batteryServer, accessInd);
        }
        break;
        default:
        {
		  /* Respond to invalid handles */
            sendBatteryReadAccessErrorRsp(batteryServer, accessInd, CSR_BT_GATT_ACCESS_RES_INVALID_HANDLE);
        }
	}
} 

#endif /* EXCLUDE_GATT_BATTERY_SERVICE_V1P1 */
